<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2010-11-30
 * Time: 15:35:25
 * To change this template use File | Settings | File Templates.
 */
 
class DbBase {
    public function getDataQuery($sqlStr)
    {
        $row_array = array();
        if($sqlStr != null)
        {
            $conn = Doctrine_Manager::connection();
            $statement=$conn->execute($sqlStr);
            $statement->setFetchMode(PDO::FETCH_ASSOC);
            $i = 0;
            while($row = $statement->fetch())
            {
                $row_array[$i] = $row;
                $i ++;
            }
        }
        return $row_array;
    }

    public function update($sqlStr)
    {
        $statement = 0;
        if($sqlStr != null)
        {
            $conn = Doctrine_Manager::connection();
            $statement=$conn->execute($sqlStr)->rowCount();
        }
        return $statement;
    }

    public static function getCatalogByID($catalogID)
    {
        $catalog = Doctrine_Core::getTable("Catalog")->find($catalogID);

    }

    public static function getRelateNews($newsID, $rContentTypeId)
    {
//        $sqlStr="select  news_id, title from News where news_id in(select r_content_id from RelatedContent where content_type_i = 1000 and content_id=".$newsID;
//        if($rContentTypeId != null)
//               $sqlStr = $sqlStr." and r_content_type_i=".$rContentTypeId;
//        $sqlStr = $sqlStr.") and status_id=1005 order by publish_time desc, news_id desc limit 1";
        $sqlStr="select  News.news_id, News.title from News,RelatedContent where News.news_id = RelatedContent.r_content_id   and RelatedContent.content_type_i = 1000 and RelatedContent.content_id=".$newsID;
        if ($rContentTypeId != null)
            $sqlStr = $sqlStr . " and RelatedContent.r_content_type_i=" . $rContentTypeId;
        $sqlStr = $sqlStr . " and News.status_id=1005 order by News.publish_time desc, News.news_id desc limit 1";




        $relatedNews = self::getDataQuery($sqlStr);
        return $relatedNews;
    }
}
